using System;
using System.Globalization;
using System.Windows.Forms;


namespace FinlogiK.FxCop.Statistics.Windows
{
	internal static class MessageBoxEx
	{
		#region Methods

		internal static DialogResult Show(string text, MessageBoxIcon icon)
		{
			return MessageBoxEx.Show(text, MessageBoxButtons.OK, icon);
		}

		internal static DialogResult Show(string text, MessageBoxButtons buttons, MessageBoxIcon icon)
		{
			return MessageBox.Show(text, string.Empty, buttons, icon, MessageBoxDefaultButton.Button1,
				MessageBoxEx.AdjustOptionsForRightToLeft());
		}

		private static MessageBoxOptions AdjustOptionsForRightToLeft()
		{
			return MessageBoxEx.AdjustOptionsForRightToLeft((MessageBoxOptions)0, null);
		}

		private static MessageBoxOptions AdjustOptionsForRightToLeft(MessageBoxOptions options, IWin32Window owner)
        {
			bool isRightToLeft = false;

            Control control = owner as Control;
			if (control != null)
			{
				isRightToLeft = control.RightToLeft == RightToLeft.Yes;
			}
			else
			{
				isRightToLeft = CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft;
			}

			MessageBoxOptions result = options;
			if (isRightToLeft) result |= MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading;

			return result;
        }

		#endregion
	}
}